<template>
    <div>
        <van-form @submit="onSubmit">
            <van-dropdown-menu>
                <van-dropdown-item v-model="form.techTypeId" :options="options" />
            </van-dropdown-menu>
            <van-field v-model="form.questionName" name="题目名称" label="题目名称" placeholder="题目名称户名"
                :rules="[{ required: true, message: '请填写题目名称' }]" />
            <van-field name="switch" label="是否必选">
                <template #input>
                    <van-switch v-model="form.isRequire" size="20" />
                </template>
            </van-field>
            <div style="margin: 16px;">
                <van-button round block type="info" native-type="submit">提交</van-button>
            </div>
        </van-form>
    </div>
</template>
<script>
import { Update, TechTypeList, Find } from "@/api/question"
export default {
    data() {
        return {
            form: {
                questionId: 0,
                techTypeId: 0,
                questionName: '',
                isRequire: true
            },
            options: [],
            selectedOptions: [],
            showPicker: false,
            selectedOption: null,
        }
    },
    computed: {
        columnData() {
            return [
                {
                    values: this.options.map((option) => option.id),
                    displayValues: this.options.map((option) => option.name),
                },
            ];
        },
    },
    methods: {
        //技术分类
        GetTechTypeList() {
            TechTypeList().then(res => {
                this.options = res.data;
                this.options.push({ text: "全部", value: 0 })
                console.log(res.data);
            })
        },
        //修改
        onSubmit() {
            Update(this.form).then(res => {
                if (res) {
                    this.$notify({ type: 'success', message: '修改成功' });
                    this.$router.push("questionlist")
                    return;
                } else {
                    this.$notify({ type: 'danger', message: '修改失败' });
                    return;
                }
            })
        },
        //反填
        FindQuestion(Id) {
            Find(Id).then(res => {
                this.form = res.data;
            })
        }
    },
    created() {
        this.GetTechTypeList();
        this.form.questionId = window.localStorage.getItem("QId");
        this.FindQuestion(this.form.questionId);
    }
}
</script>
<style></style>